﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKRevitKernel.ElementSearchUtility.LinkDocumentSuite;
using YJKPatternSign.StairsRoomPlanSign.ModelLayer;
using YJKPatternSign.StairsRoomSection.DataDefine;
using YJKPatternSign.StairsRoomSection.Manager;

namespace YJKPatternSign.StairsRoomPlanSign.ControlLayer
{
	internal class WallAndColumnFillOper
	{
		public WallAndColumnFillOper(UIDocument uiDoc, StairPlanDataPacker inputdata)
		{
			this.m_PlanDataPacker = inputdata;
			this.m_uidoc = uiDoc;
			this.m_Doc = this.m_PlanDataPacker.M_doc;
			this.m_ViewData = this.m_PlanDataPacker.UseViewData;
			this.m_lstColumn = this.m_PlanDataPacker.LstColumns;
			this.m_lstWall = this.m_PlanDataPacker.LstWalls;
		}

		public bool FillRegion()
		{
			List<BaseLinkDocumentResultBean> lstElementNeedFill = new List<BaseLinkDocumentResultBean>();
			List<RevitLinkInstance> lstLinkInstance = new List<RevitLinkInstance>();
			this.InitSectionViewAndElmentInfo(ref lstElementNeedFill, ref lstLinkInstance);
			new FillElementCls(lstElementNeedFill, lstLinkInstance, this.m_viewSecData).FilledElement();
			return true;
		}

		public void InitSectionViewAndElmentInfo(ref List<BaseLinkDocumentResultBean> elementsInLine, ref List<RevitLinkInstance> lstLinkIns)
		{
			BoundingBoxXYZ boundingBoxXYZ = this.m_ViewData.ViewPlan.get_BoundingBox(this.m_ViewData.ViewPlan);
			XYZ min = boundingBoxXYZ.Min;
			XYZ max = boundingBoxXYZ.Max;
			XYZ minPt = new XYZ(min.X, min.Y, this.m_ViewData.BottomHeightZ);
			XYZ xyz = new XYZ(max.X, max.Y, this.m_ViewData.CutHeightZ);
			this.m_viewSecData = new SectionViewData(this.m_ViewData.ViewPlan);
			this.m_viewSecData.InitViewData();
			Line secLine = this.m_viewSecData.m_SecLine;
			double z = secLine.GetEndPoint(0).Z;
			double num = xyz.Z - z;
			Transform transform = Transform.CreateTranslation(new XYZ(0.0, 0.0, num));
			this.m_viewSecData.m_SecLine = (secLine.CreateTransformed(transform) as Line);
			this.m_viewSecData.MinPt = minPt;
			this.m_viewSecData.MaxPt = xyz;
			foreach (KeyValuePair<FamilyInstance, int> keyValuePair in this.m_lstColumn)
			{
				RevitLinkInstance revitLinkInstance = null;
				if (keyValuePair.Value != -1)
				{
					ElementId elementId = new ElementId(keyValuePair.Value);
					revitLinkInstance = (this.m_Doc.GetElement(elementId) as RevitLinkInstance);
					lstLinkIns.Add(revitLinkInstance);
				}
				BaseLinkDocumentResultBean item = new BaseLinkDocumentResultBean(keyValuePair.Key, revitLinkInstance, null);
				elementsInLine.Add(item);
			}
			foreach (KeyValuePair<Wall, int> keyValuePair2 in this.m_lstWall)
			{
				RevitLinkInstance revitLinkInstance2 = null;
				if (keyValuePair2.Value != -1)
				{
					ElementId elementId2 = new ElementId(keyValuePair2.Value);
					revitLinkInstance2 = (this.m_Doc.GetElement(elementId2) as RevitLinkInstance);
					lstLinkIns.Add(revitLinkInstance2);
				}
				BaseLinkDocumentResultBean item2 = new BaseLinkDocumentResultBean(keyValuePair2.Key, revitLinkInstance2, null);
				elementsInLine.Add(item2);
			}
			lstLinkIns.Distinct<RevitLinkInstance>();
		}

		private SectionViewData m_viewSecData;

		private StairPlanDataPacker m_PlanDataPacker;

		private UIDocument m_uidoc;

		private Document m_Doc;

		private ViewData m_ViewData;

		private List<KeyValuePair<Wall, int>> m_lstWall;

		private List<KeyValuePair<FamilyInstance, int>> m_lstColumn;
	}
}
